package first.group.ssh.hostkey;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.List;

public abstract class HostKeyAlgorithm {

    public abstract String getName();

    public static abstract class HostKey<T extends HostKeyAlgorithm> {

        public abstract boolean check(byte[] data, HostSignature<? extends HostKeyAlgorithm> signature);

        public abstract T getAlgorithm();
        
        public abstract void write(ByteBuffer buffer);
    }

    public static abstract class HostKeyParser<T extends HostKeyAlgorithm> {

        public abstract HostKey<T> parse(ByteBuffer buffer) throws IOException;
    }

    public abstract HostKeyParser<? extends HostKeyAlgorithm> getKeyParser();

    public static abstract class HostSignature<T extends HostKeyAlgorithm> {

        public abstract T getAlgorithm();
    }

    public static abstract class HostSignatureParser<T extends HostKeyAlgorithm> {

        public abstract HostSignature<T> parse(ByteBuffer buffer) throws IOException;
    }

    public abstract HostSignatureParser<? extends HostKeyAlgorithm> getSignatureParser();

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        return obj.getClass().equals(this.getClass());
    }
    
    public static final List<HostKeyAlgorithm> algos = List.of(new SshRsa(), new SshEd25519());
}
